
define(function(require, exports, module){
	"require:nomunge,exports:nomunge,module:nomunge";
	//异步请求
var wind_async=require('ddf_wind_async');
	
var base=require('component-base');
var history=require('component-history');
var dialog = require('component-dialog');	
 require('component-page');

  var pageSize=10,username="",mobile="",shopId="",beginDate="",endDate="",staffId="",userId="",realName="",memo="";
  function initParameter(){
	  userId="";
	  memo="";
	  username="";
	  mobile="";
	  beginDate="";
	  endDate="";
	  staffId="";
	  userId="";
	  realName="";
  }
/**
 * 店员列表
 */
exports.init=function(m){
	history.addHis(this,arguments);//增加历史
	window.$ddf_staff = m;
	var htmlStr="";
	initParameter(); //初始化参数
	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:void(0)" class="current">店员管理</a></div>';
	htmlStr += '</div>    ';
	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips0" ></div>';
	
	//搜索条件
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon">';
	htmlStr += '<i class="icon-search"></i>';
	htmlStr += '</span>';
	htmlStr += '<h5>搜索条件</h5><button type="button" class="label label-success toggle">缩放</button>';
	htmlStr += '</div> ';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<form class="form-horizontal">';
	htmlStr += '<div class="row-fluid">';
//	htmlStr += '<div class="control-group ">';
//	htmlStr += '<label class="control-label">创建时间：</label>';
//	htmlStr += '<div class="controls">';
//	htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">申请时间：</label><div class="controls"><input class="span4 m-wrap Wdate" type="text" id="beginDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span4 m-wrap Wdate" type="text" id="endDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) /></div></div></div>';
//	
//	htmlStr += '<div class="span6">';
//	htmlStr += '</div>';
//	
//	htmlStr += '</div>';
//	
//	htmlStr += '<div class="row-fluid">';
//	
//	htmlStr += '<div class="span6">';
//	htmlStr += '<div class="control-group">';
//	htmlStr += '<label class="control-label">用户帐号：</label>';
//	htmlStr += '<div class="controls">';
//	htmlStr += '<input class="span8 m-wrap" type="text" id="userName"/>';
//	htmlStr += '</div>';
//	htmlStr += '</div>';
//	htmlStr += '</div>';;
//	
//	htmlStr += '<div class="span6">';
//	htmlStr += '<div class="control-group">';
//	htmlStr += '<label class="control-label">用户姓名：</label>';
//	htmlStr += '<div class="controls">';
//	htmlStr += '<input class="span8 m-wrap" type="text" id="realName"/>';
//	htmlStr += '</div>';
//	htmlStr += '</div>';
//	htmlStr += '</div>';
//	
//	
//	htmlStr += '</div>';
	htmlStr += '<div class="span6"><div class="control-group"><label class="control-label">申请时间：</label><div class="controls"><input class="span4 m-wrap Wdate" type="text" id="beginDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span4 m-wrap Wdate" type="text" id="endDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) /></div></div></div>';
	
	htmlStr += '<div class="span6">';
	htmlStr += '</div>';
	
	htmlStr += '</div>';
	
	htmlStr += '<div class="row-fluid">';
	
	htmlStr += '<div class="span6">';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">用户名：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span8 m-wrap" type="text" id="userName"/>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';;
	
	htmlStr += '<div class="span6">';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">真实姓名：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span8 m-wrap" type="text" id="realName"/>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	
	htmlStr += '</div>';
    htmlStr += '<div class="row-fluid">';
	
	htmlStr += '<div class="span6">';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">手机号：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span8 m-wrap" type="text" id="mobile"/>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';;
	
	htmlStr += '<div class="span6">';
	htmlStr += '<div class="control-group">';
	htmlStr += '<label class="control-label">员工号：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span8 m-wrap" type="text" id="staffId"/>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	
	htmlStr += '</div>';
	htmlStr += '<div class="form-actions">';
	htmlStr += '<button class="btn btn-primary" type="button" onClick="$ddf_staff.searchUserShop()">搜索</button>';
	htmlStr += ' <button class="btn btn-info" type="button" onClick="$ddf_staff.resetSearchParams()">重置</button>';
	htmlStr += ' <button class="btn btn-success" type="button" onClick="$ddf_staff.openAddUser()">增加</button>';
	htmlStr += '</div>';
	
	htmlStr += '</form>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	//列表
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>用户列表</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
	htmlStr += '<table class="table table-bordered data-table">';
	htmlStr += '<thead>';
	htmlStr += '<tr>';
	htmlStr += '<th>序号</th>';
	htmlStr += '<th>员工号</th>';
	htmlStr += '<th>用户代码</th>';
	htmlStr += '<th>真实姓名</th>';
	htmlStr += '<th>用户名</th>';
	htmlStr += '<th>手机号码</th>';
	htmlStr += '<th>创建时间</th>';
	htmlStr += '<th>操作</th>';
	htmlStr += '</tr>';
	htmlStr += '</thead>';
	htmlStr += '<tbody id="userList">';
	
	htmlStr += '</tbody>';
	htmlStr += '</table>';
	htmlStr += '<div id="footPageDiv0">';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	base.showLoading();
	showDiv("content0");
	$("#content0").html(htmlStr);
	getUserStaffList(1,pageSize,username,mobile,beginDate,endDate,staffId,userId,realName);
}

 function getUserStaffList(page,pageSize,username,mobile,beginDate,endDate,staffId,userId,realName){
	
	 var params={
			 "page.pageNumber":page,
			 "page.pageSize" : pageSize,
			 "username":username,
			 "mobile":mobile,
			 "beginDate":beginDate,
			 "endDate":endDate,
			 "staffId":staffId,
			 "userId":userId,
			 "realName":realName
	 };
	    base.showLoading();
		eval(Wind.compile("async",function(){
			
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.staff.getUsersList,params));
			
			getUserListCallBack(data);
			
		}))().start();
	 
 }
 
 /**
  * 商家店員的列表的回調函數
  */
 function getUserListCallBack(data){
//	 alert("商家店員的列表的回調函數");
	 if(data["code"] == 1){
		    var htmlStr ='';
			for(var i=0;i<data["userShopList"].length;i++){
				htmlStr += ' <tr>';
				htmlStr += '<td>'+base.getSequence(data["pageNumber"],data["pageSize"],i+1)+'</td>';
				htmlStr += '<td>'+data["userShopList"][i]["staffId"]+'</td>';
				htmlStr += '<td>'+data["userShopList"][i]["userId"]+'</td>';
				htmlStr += '<td>'+data["userShopList"][i]["realName"]+'</td>';
				htmlStr += '<td>'+data["userShopList"][i]["userName"]+' </td>';
				htmlStr += '<td>'+data["userShopList"][i]["mobile"]+'</td>';
				htmlStr += '<td>'+data["userShopList"][i]["createTime"]+'</td>';
				htmlStr += '<td>';
				htmlStr += '<a href=javascript:$ddf_staff.changePwd("'+data["userShopList"][i]["userId"]+'")>修改密码</a>&nbsp;&nbsp;|&nbsp;&nbsp;';
				htmlStr += '<a href=javascript:$ddf_staff.toAssignRole("'+data["userShopList"][i]["userId"]+'")>分配角色</a>';
				htmlStr += '</td>';
				htmlStr += '</tr> ';
			}			
			$("#userList").html(htmlStr);
						
			$('#footPageDiv0').ddf_pagination(data["pageSize"],data["pageNumber"],data["totalCount"],data["totalPage"],{  
				 changePageCallback:function(pageSize,page){  
					 getUserStaffList(page,pageSize,username,mobile,beginDate,endDate,staffId,userId,realName);
				 },
				 changePageSizeCallBack:function(pageSize){
					 getUserStaffList(1,pageSize,username,mobile,beginDate,endDate,staffId,userId,realName);
				 } 
	         }); 
	 }else{
		 base.tips_error(data["message"]);
	 }
	 base.cancelLoading();
 }

//修改密码
 exports.changePwd=function(id){
	 history.addHis(this,arguments);//增加历史
 	var title="修改密码";
 	var btnleft="确定";
 	var btnright="取消";
 	var changepwd=
 		'<div id="'+id+'" class="modal">' +
 			 '<div class="modal-header">' +
 				 '<button class="close over" type="button">×</button>' +
 				 '<h3>'+title+'</h3>' +
 			 '</div>' +
 			 '<div class="modal-body form-horizontal"><div class="row-fluid">'+
 				 	'<div class="control-group" id="control-group-edit-pwd"><label class="control-label">新密码：</label><div class="controls"><input type="password" id="pwd" class="span8 m-wrap"  /></div></div><div class="control-group" id="control-group-edit-pwd2"><label class="control-label">确认密码：</label><div class="controls"><input type="password" id="pwd2" class="span8 m-wrap"  /></div></div>'+
 			 '</div></div>'+
 			 '<div class="modal-footer"> <button type="button" class="btn btn-primary" onclick=$ddf_staff.updatePassword("'+id+'")>'+btnleft+'</button> <button class="btn over" type="button">'+btnright+'</button> </div>'+
 		'</div>';
 	$(changepwd).appendTo("body");
 	$("<div class='modal-backdrop in'></div>").appendTo("body");
 	$("#"+id).find(".over").click(function(){
 		$("#"+id).remove();	
 		$("body .modal-backdrop").remove();	
 	});

	/**
	 * 验证密码的长度
	 */
	$("#pwd").change(function(){
		var pwd = $("#pwd").val();

		if(!isLoginPassword(pwd)){
			base.addErrorMessage("control-group-edit-pwd","pwd","密码为6-20位数字，字母，符号组合，请重新输入!");
		}else{
			base.clearErrorMessage("control-group-edit-pwd");
		}
	});
	
	$("#pwd2").change(function(){
		var pwd = $("#pwd2").val();

		if(!isLoginPassword(pwd)){
			base.addErrorMessage("control-group-edit-pwd2","pwd2","密码为6-20位数字，字母，符号组合，请重新输入!");
		}else{
			base.clearErrorMessage("control-group-edit-pwd2");
		}
	});
 };
 
 /**
  * 确认修改密码
  */
 exports.updatePassword=function(userId){
 	
 	var pwd=$("#pwd").val();
 	
 	var pwd2=$("#pwd2").val();
 	
 	if(isNull(pwd)){
 		base.addErrorMessage("control-group-edit-pwd","pwd","新密码不能为空");
 		return;
 	}else if(!isLoginPassword(pwd)){
 		base.addErrorMessage("control-group-edit-pwd","pwd","密码为6-20位数字，字母，符号组合，请重新输入!");
 		return;
 	}else{
 		base.clearErrorMessage("control-group-edit-pwd");
 	}
 	
 	if(isNull(pwd2)){
 		base.addErrorMessage("control-group-edit-pwd2","pwd2","确认密码不能为空");
 		return;
 	}else if(!isLoginPassword(pwd2)){
 		base.addErrorMessage("control-group-edit-pwd2","pwd2","密码为6-20位数字，字母，符号组合，请重新输入!");
 		return;
 	}else{
 		base.clearErrorMessage("control-group-edit-pwd2");
 	}
 	
 	if(pwd!=pwd2){
 		base.addErrorMessage("control-group-edit-pwd2","pwd2","两次密码必须一样");
 		return;
 	}

 	var params={
 			
 			"userId":userId,
 			"password":MD5(pwd2)
 			
 	        };
 	

 	base.showLoading();
 	
 	
 	eval(Wind.compile("async",function(){
 		
 		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.staff.editUserPwd,params));
 		
 		updatePasswordCallBack(data,userId);
 		
 	}))().start();
 	
 };

 /**
  * 确认修改密码_回调函数
  */
 function updatePasswordCallBack(data,userId){
 	if(data["code"]==1){
 		
 		base.tips("密码修改成功");
 	}else{
 		
 		
 		 base.tips_error("密码修改失败");
 	}
 	
 	base.cancelLoading();
 	$("#"+userId).remove();	
	$("body .modal-backdrop").remove();	
 }

 /**
  * 搜索商家的店员
  */
 function searchUserShop(){
//	 alert("搜索商家的店员");
	 username= $("#userName").val();
	 mobile=$("#mobile").val();
	 beginDate=$("#beginDate").val();
	 endDate=$("#endDate").val();
     staffId=$("#staffId").val();
     realName=$("#realName").val();
	 if(!base.checkDate(beginDate,endDate))
		 return;
	 getUserStaffList(1,pageSize,username,mobile,beginDate,endDate,staffId,userId,realName);
 }
 
 /**
  * 重置参数
  */
 function resetSearchParams(){
//	 username="";
	 $("#userName").val("");
//	 mobile="";
	 $("#mobile").val("");
//	 beginDate="";
	 $("#beginDate").val("");
//	 endDate="";
	 $("#endDate").val("");
//     staffId="";
     $("#staffId").val("");
//     realName ="";
     $("#realName").val("");
     initParameter();
 }
 /**
  * 打开添加用户
  */
 function openAddUser(){
	 history.addHis(this,arguments);//增加历史
 	var htmlStr="";
 	 
// 	htmlStr += '<div id="content-header">';
// 	htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_staff.showDiv("content0")>用户管理</a><a href="javascript:void(0)" class="current">新增用户</a></div>';
// 	htmlStr += '</div> ';
// 	htmlStr += '<div class="container-fluid">';
// 	htmlStr += '<div class="row-fluid">';
// 	htmlStr += '<div class="span12">';
// 	htmlStr += '<div id="alert-tips7" ></div>';
// 	htmlStr +='<div id="errorMessage-addUser" style="display:none" class="alert alert-error alert-block">';
// 	htmlStr +='<a class="close" href="#" data-dismiss="alert">×</a>';
// 	htmlStr +='<h4 class="alert-heading">Error!</h4>';
// 	htmlStr +='You are not looking too good. Nulla vitae elit libero, a pharetra augue. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.';
// 	htmlStr +='</div>  ';
//     
// 	htmlStr += '<div class="widget-box">';
// 	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
// 	htmlStr += '<h5>新增用户信息</h5>';
// 	htmlStr += '</div>';
// 	htmlStr += '<div class="widget-content nopadding">';
// 	htmlStr += '<form class="form-horizontal">	   ';
// 	htmlStr += '<div class="control-group" id="control-group-username">';
// 	htmlStr += '<label class="control-label">用户账号：</label>';
// 	htmlStr += '<div class="controls">';
// 	htmlStr += '<input class="span9" type="text"  id="input-username" value="">';
// 	htmlStr += '</div>              ';
// 	htmlStr += '</div>';
// 	htmlStr += '<div class="control-group" id="control-group-password">';
// 	htmlStr += '<label class="control-label">用户密码：</label>';
// 	htmlStr += '<div class="controls">';
// 	htmlStr += '<input class="span9" type="password" id="input-password" value="">';
// 	htmlStr += '</div>              ';
// 	htmlStr += '</div>';
//// 	htmlStr += '<div class="control-group">';
//// 	htmlStr += '<label class="control-label">证件类型：</label>';
//// 	htmlStr += '<div class="controls">';
//// 	htmlStr += '<div class="btn-group">';
//// 	htmlStr += '<button data-toggle="dropdown" class="btn dropdown-toggle" ><span id="card_type_name">身份证</span>&nbsp;&nbsp;<span class="caret"></span></button>';
//// 	htmlStr += '<ul class="dropdown-menu">';
//// 	htmlStr += '<li><a href=javascript:$ddf_staff.setCardType(1,"身份证")>身份证</a></li>';
//// 	htmlStr += '<li><a href=javascript:$ddf_staff.setCardType(2,"军人证")>军人证</a></li>';
//// 	htmlStr += '<li><a href=javascript:$ddf_staff.setCardType(3,"户口本")>户口本</a></li>';
//// 	htmlStr += '</ul>';
//// 	htmlStr += '</div>';
//// 	htmlStr += '</div> ';
//// 	htmlStr += '</div>';
//// 	htmlStr += '<div class="control-group" id="control-group-identity">';
//// 	htmlStr += '<label class="control-label">证件号码：</label>';
//// 	htmlStr += '<div class="controls">';
//// 	htmlStr += '<input class="span9" type="text" id="input-identity" value="">';
//// 	htmlStr += '</div>       ';
//// 	htmlStr += '</div>';
//// 	htmlStr += '<div class="control-group">';
//// 	htmlStr += '<label class="control-label">用户性别：</label>';
//// 	htmlStr += '<div class="controls">';
//// 	htmlStr += '<label><input type="radio" name="sex" value="1" checked="checked" />男</label><label><input type="radio" name="sex" value="0"/>女</label>   ';
//// 	htmlStr += '</div>';
//// 	htmlStr += '</div>';
//// 	htmlStr += '<div class="control-group">';
//// 	htmlStr += '<label class="control-label">开户商家：</label>';
//// 	htmlStr += '<div class="controls">';
////// 	htmlStr += '<select id="select-shop">';
////// 	htmlStr += '</select>                  ';
//// 	htmlStr += '<input class="span9"  id="input-shopName" type="text" readonly onclick="$ddf_staff.openShopDialog()" />   ';
//// 	
//// 	htmlStr += '</div>';
//// 	htmlStr += '</div>';
//// 	htmlStr += '<div class="control-group" id="control-group-card">';
//// 	htmlStr += '<label class="control-label">卡号：</label>';
//// 	htmlStr += '<div class="controls">';
//// 	htmlStr += '<input class="span9" type="text" id="input-card">       ';
//// 	htmlStr += '</div>                    ';
//// 	htmlStr += '</div>';
//// 	htmlStr += '<div class="control-group" id="control-group-phoneNumber">';
//// 	htmlStr += '<label class="control-label">联系电话：</label>';
//// 	htmlStr += '<div class="controls">';
//// 	htmlStr += '<input class="span9" type="text" id="input-phoneNumber" value="">';
//// 	htmlStr += '</div>                  ';
//// 	htmlStr += '</div>';
//// 	htmlStr += '<div class="control-group" id="control-group-email">';
//// 	htmlStr += '<label class="control-label">邮箱地址：</label>';
//// 	htmlStr += '<div class="controls">';
//// 	htmlStr += '<input class="span9" type="text" id="input-email" value="">';
//// 	htmlStr += '</div>             ';
//// 	htmlStr += '</div>';
//// 	htmlStr += '<div class="control-group" id="control-group-mobile">';
//// 	htmlStr += '<label class="control-label">手机号码：</label>';
//// 	htmlStr += '<div class="controls">';
//// 	htmlStr += '<input class="span9" type="text" id="input-mobile" value="">';
//// 	htmlStr += '</div>';
//// 	htmlStr += '</div>';
//// 	htmlStr += '<div class="control-group">';
//// 	htmlStr += '<label class="control-label">真实姓名：</label>';
//// 	htmlStr += '<div class="controls">';
//// 	htmlStr += ' <input class="span9" type="text" id="input-realName" value="">';
//// 	htmlStr += '</div>';
//// 	htmlStr += '</div>';
//// 	htmlStr += '<div class="control-group">';
//// 	htmlStr += '<label class="control-label">所在地址：</label>';
//// 	htmlStr += '<div class="controls">';
//// 	htmlStr += '<input class="span9" type="text" id="input-address" value="">';
//// 	htmlStr += '</div>';
//// 	htmlStr += '</div>';
// 	htmlStr += '<div class="form-actions">';
// 	htmlStr += '<button class="btn btn-primary" type="button" onClick="$ddf_staff.saveUserStaff()" >保存</button> ';
// 	htmlStr += '<button class="btn btn-info" type="button" onClick=$ddf_staff.showDiv("content0")>返回</button>  ';
// 	htmlStr += '</div>  ';
// 	htmlStr += '</form>';
// 	htmlStr += '</div>';
// 	htmlStr += '</div>  ';
// 	htmlStr += '</div>';
// 	htmlStr += '</div> ';
// 	htmlStr += '</div> ';
 	
    var htmlStr="";
	
	htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:$ddf_bank.showDiv("content0")>店员管理</a><a href="javascript:void(0)" class="current">添加店员</a></div></div>';
	htmlStr += '<div class="container-fluid">';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips1" ></div>';
	
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>增加店员</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content nopadding">';
	htmlStr += '<form class="form-horizontal">	   ';
	
	htmlStr += '<div class="control-group" id="control-group-bankId" >';
	htmlStr += '<label class="control-label">用户代码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span4 alert_w"  id="input-userId" type="text" value="请选择用户" readonly onclick="$ddf_staff.openUserListDialog()" />';

	htmlStr += '</div>';
	htmlStr += '</div>';
	
//	htmlStr += '<div class="control-group">';
//	htmlStr += '<label class="control-label">账户类型：</label>';
//	htmlStr += '<div class="controls">';
//	htmlStr += '<div class="btn-group"><button data-toggle="dropdown" class="btn dropdown-toggle" ><span id="account_type_name">银行卡</span>&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu">';
//	htmlStr += '<li><a href=javascript:$ddf_bank.setAccountType("00","银行卡")>银行卡</a></li>';
//	htmlStr += '<li><a href=javascript:$ddf_bank.setAccountType("01","银行存折")>银行存折</a></li>';
//	htmlStr += '</ul></div> ';
//	htmlStr += '</div>    ';
//	htmlStr += '</div>';
	
	
	htmlStr += '<div class="control-group" id="control-group-bankNumber">';
	htmlStr += '<label class="control-label">用户名：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span4" type="text" readonly id="input-userName" value="">';
	htmlStr += '</div>              ';
	htmlStr += '</div>';

	htmlStr += '<div class="control-group" id="control-group-accountName">';
	htmlStr += '<label class="control-label">真实姓名：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span4" type="text" readonly id="input-realName" value="">';
	htmlStr += '</div>              ';
	htmlStr += '</div>';
	
//	htmlStr += '<div class="control-group" id="control-group-identity">';
//	htmlStr += '<label class="control-label">邮箱地址：</label>';
//	htmlStr += '<div class="controls">';
//	htmlStr += '<input class="span4" type="text" readonly id="input-email" value="">';
//	htmlStr += '</div>       ';
//	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group" id="control-group-mobile">';
	htmlStr += '<label class="control-label">手机号码：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span4" type="text" readonly id="input-mobile">       ';
	htmlStr += '</div>                    ';
	htmlStr += '</div>';
	
	htmlStr += '<div class="control-group" id="control-group-mobile">';
	htmlStr += '<label class="control-label">店员备注：</label>';
	htmlStr += '<div class="controls">';
	htmlStr += '<input class="span4" type="text"  id="input-memo">       ';
	htmlStr += '</div>';
	htmlStr += '</div>';
	
	htmlStr += '<div class="form-actions">';
	htmlStr += '<button class="btn btn-primary" id="btnBindBankCard" type="button" onclick="$ddf_staff.saveUserStaff()">增加</button> ';
	htmlStr += '<button class="btn btn-info" type="button" onClick=$ddf_staff.showDiv("content0")>返回</button>  ';
	htmlStr += '</div>  ';
	htmlStr += '</form>';
	htmlStr += '</div>';
	htmlStr += '</div>  ';
	
	
	htmlStr += '</div>  ';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div> ';
 	
 	showDiv("content1");

 	$("#content1").html(htmlStr);
 	
 	
 }
 
 function saveUserStaff(){
	    userId = $("#input-userId").val();  
	    memo = $("#input-memo").val();
//	    alert(userId+":"+memo);
		var params={
				"userId": userId,
				"memo":memo
		        };
		base.showLoading();
		eval(Wind.compile("async",function(){
			var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.staff.addUsersStaff,params));
			saveUsersCallBack(data);
		}))().start();
 }
 /**
  * 新增用户的回调函数
  */
function saveUsersCallBack(data){
	if(data["code"] == 1){
		showDiv("content0");
		base.tips(data["message"]);
		initParameter(); //初始化
		getUserStaffList(1,pageSize,username,mobile,beginDate,endDate,staffId,userId,realName);
	}else{
		 base.tips_error(data["message"]);
	}
	base.cancelLoading();
}
 
/**
 * 显示DIV
 */
 function showDiv(block){
	
	$("#content > div").hide();
	
	if($("#"+block).length<=0){
		
		$("#content").append('<div id="'+block+'"></div>'); 
		
	}else{
		
		$("#"+block).show();
	}
	
}
 /**
  * 弹出用户列表
  */
 function openUserListDialog(){
	 dialog.ddf_dialog_member($("#input-userId"),function(userId,userName,mobile,realName){
		 $("#input-userId").val(userId);
		 $("#input-userName").val(userName);
		 $("#input-mobile").val(mobile);
		 $("#input-realName").val(realName);
//		 $("#input-email").val(email);
	 });
 }
 
 
 /**
  * 分配角色
  */
 function toAssignRole(userId){
	 history.addHis(this,arguments);//增加历史
 	
 	
 	var htmlStr="";

 	htmlStr += '<div id="content-header">';
 	htmlStr += '<div id="breadcrumb"> <a href=javascript:$ddf_base.load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_staff.showDiv("content0")>店员管理</a><a href="javascript:void(0)" class="current">分配角色</a></div>';
 	htmlStr += '</div>    ';
 	htmlStr += '<div class="container-fluid">';
 	htmlStr += '<div class="row-fluid">';
 	htmlStr += '<div class="span12">';
 	htmlStr += '<div id="alert-tips4" ></div>';
 	htmlStr +='<div id="errorMessage-assignRole" style="display:none" class="alert alert-error alert-block">';
 	htmlStr +='<a class="close" href="#" data-dismiss="alert">×</a>';
 	htmlStr +='<h4 class="alert-heading">Error!</h4>';
 	htmlStr +='You are not looking too good. Nulla vitae elit libero, a pharetra augue. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.';
 	htmlStr +='</div>  ';
 	
 	htmlStr += '<div class="widget-box">';
 	htmlStr += '<div class="widget-title">';
 	htmlStr += '<span class="icon"><i class="icon-pencil"></i></span>';
 	htmlStr += '<h5>操作</h5>';
 	htmlStr += '</div>        ';
 	htmlStr += '<div class="widget-content">';
 	htmlStr += '<div class="div-btn">';
 	htmlStr += ' <button class="btn btn-primary" type="button" onClick=$ddf_staff.assignRole("'+userId+'")>确认分配</button>  ';
 	htmlStr += ' <button class="btn btn-info" type="button" onClick=$ddf_staff.showDiv("content0")>返回</button> ';
 	htmlStr += '</div>';
 	htmlStr += '</div>';
 	htmlStr += '</div>	';
 	htmlStr += '<div class="widget-box">';
 	htmlStr += '<div class="widget-title"> <span class="icon">';
 	htmlStr += '<input type="checkbox" id="title-checkbox" name="title-checkbox" onclick=$ddf_staff.selectAll(this.checked); />';
 	htmlStr += '</span>';
 	htmlStr += '<h5>分配角色</h5>';
 	htmlStr += '</div>';
 	htmlStr += '<div class="widget-content nopadding">';
 	htmlStr += '<table class="table table-bordered table-striped with-check">';
 	htmlStr += '<thead>';
 	htmlStr += '<tr>';
 	htmlStr += '<th><i class="icon-tag"></i></th>';
 	htmlStr += '<th>序号</th>';
 	htmlStr += '<th>角色代码</th>';
 	htmlStr += '<th>角色名称</th>';
 	htmlStr += '</tr>';
 	htmlStr += '</thead>';
 	htmlStr += '<tbody id="roleList">';
 	htmlStr += '</tbody>';
 	htmlStr += '</table>';
 	htmlStr += '</div>';
 	htmlStr += '</div>  ';
 	htmlStr += '</div> ';
 	htmlStr += '</div>  ';
 	htmlStr += '</div> ';
 	
 	showDiv("content2");
 	
 	$("#content2").html(htmlStr);
 	
 	
 	
 	var params={
 			
 			"formMap.USER_ID":userId
 	};
 		
 	base.showLoading();
 	

 	eval(Wind.compile("async",function(){
 		
 		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.staff.toAssignRole,params));
 		
 		toAssignRoleCallBack(data);
 		
 	}))().start();
 	
 }

 /**
  * 分配角色_回调函数
  */
 function toAssignRoleCallBack(data){
 	
 	    if(data["code"]==1){
 	    	
 	    	var htmlStr="";

 			for(var i=0;i<data["roleListData"].length;i++){
 				

 				htmlStr += '<tr>';
 				
 				if(data["roleListData"][i]["CHECKED"]==1){

 					htmlStr += '<td><input type="checkbox" name="chk" value="'+data["roleListData"][i]["ROLE_ID"]+'" checked/></td>';
 				}else{
 					
 					htmlStr += '<td><input type="checkbox" name="chk" value="'+data["roleListData"][i]["ROLE_ID"]+'" /></td>';
 				}
 				htmlStr += '<td>'+(i+1)+'</td>';
 				htmlStr += '<td>'+data["roleListData"][i]["ROLE_ID"]+'</td>';
 				htmlStr += '<td>'+data["roleListData"][i]["ROLE_NAME"]+'</td>';
 				htmlStr += '</tr>';
 				
 			}
 		
 			$("#roleList").html(htmlStr);
 		
 	    	
 	   }else{
 		   
 		   base.tips_error(data["message"])
 		   
 	   }
 	    
 	  base.cancelLoading();
 		
 }

 /**
  * 确认分配
  */
 function assignRole(userId){
	 history.addHis(this,arguments);//增加历史
 	
 	  var id = "";
 	  var chk = document.getElementsByName("chk");
 		for (var i = 0; i < chk.length; i++) {
 			if (chk[i].checked) {
 	            if(i!=0){
 	            	id+=",";
 	            }
 	            id += chk[i].value;
 			}
 		}
 		
 			
 		//location="${ctx}/admin/Role/assignRole.do?formMap.ROLE_ID="+id+"&formMap.USER_ID=${formMap.USER_ID}";
 		var params={
 				
 				"formMap.USER_ID":userId,
 				"formMap.ROLE_ID":id
 		};
 		
 	base.showLoading();
 	
 	
 	eval(Wind.compile("async",function(){
 		
 		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.staff.assignRole,params));
 		
 		assignRoleCallBack(data);
 		
 	}))().start();
 }

 /**
  * 确认分配_回调函数
  */
 function assignRoleCallBack(data){
 	
 	
 	if(data["code"]==1){
 		
 		showDiv("content2");
 		
 		base.tips("角色分配成功");
 		
 	}else{
 		
 		base.tips_error(data["message"])

 	}
 	
 	base.cancelLoading();
 }
 
 
 
//公共方法
 exports.openUserListDialog=openUserListDialog;
 exports.showDiv = showDiv;
 exports.searchUserShop=searchUserShop;
 exports.openAddUser=openAddUser;
 exports.saveUserStaff=saveUserStaff;
 exports.resetSearchParams=resetSearchParams;
 exports.toAssignRole=toAssignRole;
 exports.assignRole=assignRole;
});
